<?php
namespace Addons\Auth\Controller;
class CheckController extends \Addon
{
    public function __construct()
    {
        parent::__construct();


    }

    /**
     * 权限限制
     * @return
     */
    public function index($parm)
    {
        if (session('isSuper')) return true;
        $admin_id = $parm['admin_id'];
        $authcode1 = BOX_MODULE_NAME . "/" . CONTROLLER_NAME . "/" . ACTION_NAME; //box
        $authcode2 = MODULE_NAME . "/" . CONTROLLER_NAME . "/" . ACTION_NAME; //
        $authcode3 = "Addon/" . ADDON_NAME . "/" . ADDON_CLASS . "/" . ADDON_METHOD; //插件权限控制
        $where = "authcode in ('$authcode1','$authcode2','$authcode3')";
        $r = BoxModel("addon_auth")->where($where)->select();
        if (!$r) return;
        $admin_id = session("admin_id");
        $auths = BoxModel("addon_auth_access")->where("admin_id='$admin_id'")->find();
        $access = explode(",", $auths['access']);
        $falg = 1;
        foreach ($r as $one) {
            if (in_array($one['id'], $access)) $falg = $falg * 0;
        }
        if ($falg == 1) {
            $this->display();
            exit();
        } else {
            return true;
        }
    }


}